﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace EAILogWebSite.Models
{
    public class LogEntity
    {
        public int Id { get; set; }
        public DateTime? LogDateTime { get; set; }
        public string MsgType { get; set; }
        public string SenderID { get; set; }
        public string ReceiverID { get; set; }
        public string SrvOpName { get; set; }
        public string MsgID { get; set; }
        public string CorrID { get; set; }
        public string ESBRspCode { get; set; }
        public string MsgBody { get; set; }
        public string Field5 { get; set; }
        public string Duration
        {
            get
            {
                if (string.IsNullOrEmpty(Field5))
                    return "N/A";

                Regex x = new Regex(@"\[(?<content>.*?)\]");

                var mc = x.Matches(Field5);
                if (mc.Count < 2) return "N/A";
                var duration = DateTime.Parse(mc[mc.Count - 1].Groups["content"].Value)
                    - DateTime.Parse(mc[0].Groups["content"].Value);

                return duration.ToString();
                //return string.Format("{0:hh:mm:ss}", duration);
            }
        }
    }
}